<template>
	<view class="new-users copy-data">
		<!-- 搜索框 -->
		<view class="searchBox">
			<uni-search-bar radius="30" placeholder="请输入关键字" clearButton="auto" cancelButton="none" @confirm="search" />
		</view>
		<!-- 订单 列表 -->
		<view class="orderBox" v-for="(item, index) in queueFreeList" :key="index">
			<view class="topUser">
				<view style="width: 40%;">
					<p>{{ item.msqUser && item.msqUser.nickname }}</p>
					<p>UID：{{item.msqUser &&  item.msqUser.uid }}</p>
				</view>
				<view style="width: 40%;color: #1D85E1;text-align: right;">
					排队顺序：{{ item.sort }}/{{item.count}}
				</view>
			</view>
			<view class="bottomMoney">
				<p>已返利：{{ item.rebate }}</p>
				<p>剩余返利：{{ item.residualRebate }}</p>
				<p>支付金额：{{ item.msqOrder && item.msqOrder.money }}</p>
				<p style="width: 100%;">订单编号：{{ item.msqOrder && item.msqOrder.orderNo }}</p>
			</view>
		</view>
		<!-- 加载提示 -->
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '@/api/user.js';
	import {
		getQueueFree
	} from '@/api/business.js';

	export default {
		data() {
			return {
				userInfo: {},
				queueFreeList: [],
				pageSize: 10, // 每页显示条目数
				pageNum: 1, // 当前页码
			};
		},
		onLoad() {
			this.getUserDetail();
		},
		methods: {
			getUserDetail() {
				getUserInfo().then((res) => {
					this.userInfo = res.data;
					this.getQueueFreeList();
				});
			},

			async getQueueFreeList() {
				const data = {
					storeId: this.userInfo.msqStore.id,
					pageSize: this.pageSize,
					pageNum: this.pageNum,
				};
				try {
					const res = await getQueueFree(data);
					const newList = res.data.records || []; // 假设返回的数据结构有一个records字段
					// 追加到现有列表
					this.queueFreeList = this.queueFreeList.concat(newList);
					// 更新当前页码
					this.pageNum++;
				} catch (error) {
					console.error('获取订单列表失败:', error);
				}
			},
			search(e) {
				// 处理搜索逻辑
				console.log('Search keyword:', e.value);
			}
		},
		onReachBottom() {
			// 触底加载更多
			this.getQueueFreeList(this.userInfo.msqStore.id);
		}
	};
</script>

<style lang="scss" scoped>
	page,
	body {
		height: 100%;
	}

	.searchBox {
		background-color: #fff;
		padding: 20rpx;
	}


	.orderBox {
		display: flex;
		flex-direction: column;
		padding: 36rpx 43rpx;
		margin: 30rpx;
		border-radius: 20rpx;
		background: #fff;

		.topUser {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-bottom: 2rpx solid #1D85E1;
			padding-bottom: 10rpx;

			.avatar {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
			}

			p {
				margin: 0;
			}
		}

		.bottomMoney {
			display: flex;
			flex-wrap: wrap;
			color: #666666;
			background-color: #F6F6F6;
			padding: 10rpx;

			p {
				width: 50%;
				margin: 10rpx 0rpx;
			}
		}
	}

	.loading {
		text-align: center;
		color: #999;
		padding: 20rpx;
	}

	.no-more {
		text-align: center;
		color: #ccc;
		padding: 20rpx;
	}
</style>